<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>图书上架</title>
	<meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(function(){
            $("#banId").focus();
        });
        function EnterPress(obj, e) { //传入 event
            var e = e || window.event;
            if (e.keyCode == 13) {
                setBookShelf(obj);
            }
        }
        function setBookShelf(obj) {
            var shelfId = $("#shelfId").val();
            var setTypeValue=$('input:radio[name="settyperadio"]:checked').val();
            if(setTypeValue==null){
                alert("请确认是否使用ISBN进行书架设置!");
                return;
            }
            if(!shelfId || '' == shelfId){
                top.$.jBox.tip("请先选择书架号!", "error", {persistent: true, opacity: 0});
            }else{
                var setSerNumnber = $(obj).val();
                $.ajax({
                    type: "POST",
                    url: "${ctx}/book/store/setBookShelf",
                    data: {shelfId: shelfId, setSerNumnber: setSerNumnber, setTypeValue: setTypeValue},
                    dataType: "json",
                    success: function (result) {
                        var code = result.code;
                        var msg = result.msg;
                        if(code == '0001'){
                            showTip(msg,"success");

                            $(".banId_td").each(function(){
                                if(banId == $(this).html()){
                                    $(this).parent().remove();
                                }
                            });

                            addBatchDetail();
                        }else{
                            showTip(msg,"warning");
                        }
                    }
                });
            }
        }
        var index = 1;
        function addBatchDetail() {
            var shelfName = $("#shelfName").val();
            var banId = $("#banId").val();
            $(".shelfName").val(shelfName);

            var html = "<tr><td>"+index+"</td>"
                     + "<td class='banId_td'>"+banId+"</td>"
                     + "<td>" + shelfName + "</td>"
                     + "<td><a href='javascript:void(0);' onclick='clearBookShelf("+banId+",this)'>删除</a></td></tr>";
            $("#newTr").after(html);
            index++;
            $(".shelfIndex").html(index);
            $("#banId").val('').focus();
        }
        function clearBookShelf(setSerNumnber,obj) {
            var shelfId = "";
            var setTypeValue=$('input:radio[name="settyperadio"]:checked').val();
            if(setTypeValue==null){
                alert("请确认是否使用ISBN进行书架删除设置!");
                return;
            }
            confirmx("确定要将这本书从书架移除么?",function(){
                $.ajax({
                    type: "POST",
                    url: "${ctx}/book/store/setBookShelf",
                    data: {shelfId: shelfId, setSerNumnber: setSerNumnber, setTypeValue: setTypeValue},
                    dataType: "json",
                    success: function (result) {
                        var code = result.code;
                        var msg = result.msg;
                        if (code == '0001') {
                            $(obj).parent().parent().remove();

							$(".banId_td").each(function(){
								if(setSerNumnber == $(this).html()){
									$(this).parent().remove();
								}
							});
                            showTip(msg, "success");
                        } else {
							showTip(msg, "warning");
                        }
                    }
                });
            });
        }
    </script>
</head>
<body>
	<form:form id="searchForm" class="breadcrumb form-search">
        <ul>
            <li>
                <label >是否使用ISBN进行书架设置:</label>
                <input type="radio" name="settyperadio"  value="1" /><label >是</label>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="settyperadio" value="0" /><label >否</label>
            </li>
        </ul>
        <br>
        <ul class="ul-form">
			<li><label>书架：</label>
				<sys:treeselect id="shelf" name="parent.id" value="" labelName="parent.name" labelValue=""
								title="选择书架" url="/shelf/bkShelf/treeData" cssClass="" allowClear="true"/>
			</li>
			<li class="clearfix"></li>
		</ul>

	</form:form>
	<table id="treeTable" class="table table-striped table-bordered table-condensed" style="width: 700px">
		<thead>
			<tr>
				<th width="30">序号</th>
				<th width="200">ISBN/条码号</th>
				<th>书架号</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="treeTableList">
		<tr id="newTr">
			<td><span class="shelfIndex">1</span></td>
			<td>
                <input id="banId" name="banId" type="text" style="width: 150px;" onkeypress="EnterPress(this,event)">
			</td>
			<td>
                <span type="shelfName"></span>
			</td>
			<td>
			</td>
		</tr>
		</tbody>
	</table>
</body>
</html>